<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<?php
set_time_limit(0);
$root=preg_replace('/cron$/', '', dirname(__FILE__));

require_once($root."inc.config.php");

require_once($root."initialize.php");

$no=0;
$uid = $_GET['uid'];
$ucode = $_GET['ucode'];
if(($db_msg=cron_initialize()) !== true){
	print_r("Connection error");
}else{
	if($uid>0)
		$record_sql="select gg_users.name, gg_users.ic, gg_users.address, gg_users.address2, gg_users.city, gg_users.zip, gg_users.state, gg_users.country, gg_users.homeno, gg_users.mobileno, gg_users.bank_name, gg_users.bank_acc_no, sum(gg_share.total_unit) as total_share from gg_users inner join gg_users sponsor on sponsor.id=".$uid." and gg_users.ref_left between sponsor.ref_left and sponsor.ref_right left join gg_share on gg_share.uid=gg_users.id and gg_share.sell_price='0.00' and gg_share.replica=0 where gg_users.id not in (81,934) and gg_users.status='normal' group by gg_users.name";
	elseif($ucode<>"")
		$record_sql="select gg_users.name, gg_users.ic, gg_users.address, gg_users.address2, gg_users.city, gg_users.zip, gg_users.state, gg_users.country, gg_users.homeno, gg_users.mobileno, gg_users.bank_name, gg_users.bank_acc_no, sum(gg_share.total_unit) as total_share from gg_users inner join gg_users sponsor on sponsor.code=".$ucode." and gg_users.ref_left between sponsor.ref_left and sponsor.ref_right left join gg_share on gg_share.uid=gg_users.id and gg_share.sell_price='0.00' and gg_share.replica=0 where gg_users.id not in (81,934) and gg_users.status='normal' group by gg_users.name";
	else
		$record_sql="select gg_users.name, gg_users.ic, gg_users.address, gg_users.address2, gg_users.city, gg_users.zip, gg_users.state, gg_users.country, gg_users.homeno, gg_users.mobileno, gg_users.bank_name, gg_users.bank_acc_no, sum(gg_share.total_unit) as total_share  from gg_users left join gg_share on gg_share.uid=gg_users.id and gg_share.sell_price='0.00' and gg_share.replica=0 and gg_share.status=0 where gg_users.id not in (81,934) and gg_users.status='normal' group by gg_users.name";

	$t = @mysql_num_rows($r=mysql_query($record_sql));
	
	if($t<=0)
	{
		print_r("no record");
		exit;
	}
	
	echo "<table border='1'><tr><td>No.</td><td>Name</td><td>IC</td><td>Address</td><td>City</td><td>Zip</td><td>State</td><td>Country</td><td>Home No.</td><td>Mobile No.</td><td>Bank Name</td><td>Bank Account No.</td></tr>";
	$i=0;
	$total=0;
	while($user = mysql_fetch_assoc($r))
	{	
		if($user["total_share"]>0){	
			$i++;
			echo "<tr><td>".$i."</td><td>".$user['name']."</td><td>".$user['ic']."</td><td align='right'>".$user['address']."</td><td align='right'>".$user['city']."</td><td align='right'>".$user['zip']."</td><td align='right'>".$user['state']."</td><td align='right'>".$user['country']."</td><td align='right'>".$user['homeno']."</td><td align='right'>".$user['mobileno']."</td><td align='right'>".$user['bank_name']."</td><td align='right'>".$user['bank_acc_no']."</td></tr>";
			$total+=number_format(($user['total_share']*3.7)+$user['ewallet']+$user['mwallet'],2,".","");
		}
	}
	echo "</table>";

}

exit;		
?>